﻿using System;
using System.Diagnostics;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

// Token: 0x02000341 RID: 833
internal class CityCreationPopUp : MonoBehaviour
{
	// Token: 0x17000366 RID: 870
	// (get) Token: 0x0600158C RID: 5516 RVA: 0x0008CEB2 File Offset: 0x0008B0B2
	// (set) Token: 0x0600158B RID: 5515 RVA: 0x0008CEA9 File Offset: 0x0008B0A9
	public int PopModifierValue { get; private set; }

	// Token: 0x17000367 RID: 871
	// (get) Token: 0x0600158E RID: 5518 RVA: 0x0008CEC3 File Offset: 0x0008B0C3
	// (set) Token: 0x0600158D RID: 5517 RVA: 0x0008CEBA File Offset: 0x0008B0BA
	public int CityRadiusValue { get; private set; }

	// Token: 0x17000368 RID: 872
	// (get) Token: 0x06001590 RID: 5520 RVA: 0x0008CED4 File Offset: 0x0008B0D4
	// (set) Token: 0x0600158F RID: 5519 RVA: 0x0008CECB File Offset: 0x0008B0CB
	public int SkyScraperHeightValue { get; private set; }

	// Token: 0x17000369 RID: 873
	// (get) Token: 0x06001592 RID: 5522 RVA: 0x0008CEE5 File Offset: 0x0008B0E5
	// (set) Token: 0x06001591 RID: 5521 RVA: 0x0008CEDC File Offset: 0x0008B0DC
	public int OpenSpaceChanceValue { get; private set; }

	// Token: 0x1700036A RID: 874
	// (get) Token: 0x06001594 RID: 5524 RVA: 0x0008CEF6 File Offset: 0x0008B0F6
	// (set) Token: 0x06001593 RID: 5523 RVA: 0x0008CEED File Offset: 0x0008B0ED
	public bool AutoPoplulate { get; private set; }

	// Token: 0x1700036B RID: 875
	// (get) Token: 0x06001596 RID: 5526 RVA: 0x0008CF07 File Offset: 0x0008B107
	// (set) Token: 0x06001595 RID: 5525 RVA: 0x0008CEFE File Offset: 0x0008B0FE
	public string SeedValue { get; private set; }

	// Token: 0x14000003 RID: 3
	// (add) Token: 0x06001597 RID: 5527 RVA: 0x0008CF10 File Offset: 0x0008B110
	// (remove) Token: 0x06001598 RID: 5528 RVA: 0x0008CF48 File Offset: 0x0008B148
	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private event Action OnAccept;

	// Token: 0x14000004 RID: 4
	// (add) Token: 0x06001599 RID: 5529 RVA: 0x0008CF80 File Offset: 0x0008B180
	// (remove) Token: 0x0600159A RID: 5530 RVA: 0x0008CFB8 File Offset: 0x0008B1B8
	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private event Action OnCancel;

	// Token: 0x14000005 RID: 5
	// (add) Token: 0x0600159B RID: 5531 RVA: 0x0008CFF0 File Offset: 0x0008B1F0
	// (remove) Token: 0x0600159C RID: 5532 RVA: 0x0008D028 File Offset: 0x0008B228
	[DebuggerBrowsable(DebuggerBrowsableState.Never)]
	private event Action OnValueChanged;

	// Token: 0x0600159D RID: 5533 RVA: 0x0008D060 File Offset: 0x0008B260
	private void Start()
	{
		this.PopModifierValue = 0;
		this.CityRadiusValue = 80;
		this.SkyScraperHeightValue = 0;
		this.OpenSpaceChanceValue = 100;
		Text[] componentsInChildren = base.transform.GetComponentsInChildren<Text>();
		componentsInChildren[1].text = "Population Modifier";
		componentsInChildren[2].text = "City radius";
		componentsInChildren[3].text = "Skyscraper height";
		componentsInChildren[4].text = "Open space chance";
		Button[] componentsInChildren2 = base.transform.GetComponentsInChildren<Button>();
		componentsInChildren2[0].onClick.AddListener(new UnityAction(this.Accept));
		componentsInChildren2[1].onClick.AddListener(new UnityAction(this.Close));
		this.popModifier = this.GetSliderByTag(componentsInChildren[1]);
		this.cityRadius = this.GetSliderByTag(componentsInChildren[2]);
		this.SkyScraperHeight = this.GetSliderByTag(componentsInChildren[3]);
		this.OpenSpaceChance = this.GetSliderByTag(componentsInChildren[4]);
		Toggle[] componentsInChildren3 = base.transform.GetComponentsInChildren<Toggle>();
		componentsInChildren3[0].onValueChanged.AddListener(new UnityAction<bool>(this.AutoPopulateSet));
		InputField[] componentsInChildren4 = base.transform.GetComponentsInChildren<InputField>();
		this.seedField = componentsInChildren4[0];
		this.seedField.characterLimit = 32;
		this.seedField.onValueChanged.AddListener(new UnityAction<string>(this.SeedChanged));
		this.seedField.onEndEdit.AddListener(delegate(string A_0)
		{
			GameController.Instance.SetIsTyping(false);
		});
		if (GameController.IsMultiplayer())
		{
			componentsInChildren3[0].enabled = false;
			this.AutoPoplulate = false;
		}
		this.SetMinMaxToSlider(this.popModifier, -100, 100, this.PopModifierValue);
		this.SetMinMaxToSlider(this.cityRadius, 80, 350, this.CityRadiusValue);
		this.SetMinMaxToSlider(this.SkyScraperHeight, 0, 100, this.SkyScraperHeightValue);
		this.SetMinMaxToSlider(this.OpenSpaceChance, 0, 100, this.OpenSpaceChanceValue);
		this.ReloadValues();
		this.popModifier.onValueChanged.AddListener(new UnityAction<float>(this.PopulationChanged));
		this.cityRadius.onValueChanged.AddListener(new UnityAction<float>(this.CityRadiusChanged));
		this.SkyScraperHeight.onValueChanged.AddListener(new UnityAction<float>(this.SkyScraperHeightChanged));
		this.OpenSpaceChance.onValueChanged.AddListener(new UnityAction<float>(this.OpenSpacesChanged));
		this.popModifier.interactable = true;
	}

	// Token: 0x0600159E RID: 5534 RVA: 0x0008D2CA File Offset: 0x0008B4CA
	private void Update()
	{
		if (this.seedField != null && this.seedField.isFocused && !GameController.Instance.userIsTyping)
		{
			GameController.Instance.SetIsTyping(true);
		}
	}

	// Token: 0x0600159F RID: 5535 RVA: 0x0008D307 File Offset: 0x0008B507
	private void AutoPopulateSet(bool populationValue)
	{
		this.AutoPoplulate = populationValue;
		this.OnValueChanged();
	}

	// Token: 0x060015A0 RID: 5536 RVA: 0x0008D31B File Offset: 0x0008B51B
	private void Close()
	{
		this.Deconstruct();
		this.OnCancel();
	}

	// Token: 0x060015A1 RID: 5537 RVA: 0x0008D32E File Offset: 0x0008B52E
	private void OpenSpacesChanged(float newvalue)
	{
		this.OpenSpaceChanceValue = (int)newvalue;
	}

	// Token: 0x060015A2 RID: 5538 RVA: 0x0008D338 File Offset: 0x0008B538
	private void SkyScraperHeightChanged(float newvalue)
	{
		this.SkyScraperHeightValue = (int)newvalue;
		this.OnValueChanged();
	}

	// Token: 0x060015A3 RID: 5539 RVA: 0x0008D34D File Offset: 0x0008B54D
	private void CityRadiusChanged(float newvalue)
	{
		this.CityRadiusValue = (int)newvalue;
		this.OnValueChanged();
	}

	// Token: 0x060015A4 RID: 5540 RVA: 0x0008D362 File Offset: 0x0008B562
	private void PopulationChanged(float newvalue)
	{
		this.PopModifierValue = (int)newvalue;
	}

	// Token: 0x060015A5 RID: 5541 RVA: 0x0008D36C File Offset: 0x0008B56C
	private void SeedChanged(string newValue)
	{
		this.SeedValue = newValue;
	}

	// Token: 0x060015A6 RID: 5542 RVA: 0x0008D378 File Offset: 0x0008B578
	private void ReloadValues()
	{
		this.popModifier.value = (float)this.PopModifierValue;
		this.cityRadius.value = (float)this.CityRadiusValue;
		this.SkyScraperHeight.value = (float)this.SkyScraperHeightValue;
		this.OpenSpaceChance.value = (float)this.OpenSpaceChanceValue;
		this.seedField.text = this.SeedValue;
	}

	// Token: 0x060015A7 RID: 5543 RVA: 0x0008D3DE File Offset: 0x0008B5DE
	private void Accept()
	{
		this.Deconstruct();
		this.OnAccept();
	}

	// Token: 0x060015A8 RID: 5544 RVA: 0x0008D3F4 File Offset: 0x0008B5F4
	private void Deconstruct()
	{
		UnityEngine.Object.Destroy(base.gameObject);
		this.popModifier.onValueChanged.RemoveAllListeners();
		this.SkyScraperHeight.onValueChanged.RemoveAllListeners();
		this.OpenSpaceChance.onValueChanged.RemoveAllListeners();
		this.cityRadius.onValueChanged.RemoveAllListeners();
		this.seedField.onValueChanged.RemoveAllListeners();
		Button[] componentsInChildren = base.transform.GetComponentsInChildren<Button>();
		foreach (Button button in componentsInChildren)
		{
			button.onClick.RemoveAllListeners();
		}
		Toggle[] componentsInChildren2 = base.transform.GetComponentsInChildren<Toggle>();
		foreach (Toggle toggle in componentsInChildren2)
		{
			toggle.onValueChanged.RemoveAllListeners();
		}
	}

	// Token: 0x060015A9 RID: 5545 RVA: 0x0008D4CA File Offset: 0x0008B6CA
	public void SetHandlers(Action onAccept, Action onCancel, Action onValueChanged)
	{
		this.OnAccept = onAccept;
		this.OnCancel = onCancel;
		this.OnValueChanged = onValueChanged;
		base.gameObject.SetActive(true);
	}

	// Token: 0x060015AA RID: 5546 RVA: 0x0008D4F0 File Offset: 0x0008B6F0
	private Slider GetSliderByTag(Text tag)
	{
		Slider component = tag.transform.parent.parent.GetComponent<Slider>();
		if (component == null)
		{
			UnityEngine.Debug.LogError("Slider not found");
		}
		return component;
	}

	// Token: 0x060015AB RID: 5547 RVA: 0x0008D52A File Offset: 0x0008B72A
	private void SetMinMaxToSlider(Slider slider, int min, int max, int initialValue)
	{
		slider.maxValue = (float)max;
		slider.minValue = (float)min;
		slider.value = (float)initialValue;
	}

	// Token: 0x0400185E RID: 6238
	private Slider popModifier;

	// Token: 0x0400185F RID: 6239
	private Slider cityRadius;

	// Token: 0x04001860 RID: 6240
	private Slider SkyScraperHeight;

	// Token: 0x04001861 RID: 6241
	private Slider OpenSpaceChance;

	// Token: 0x04001862 RID: 6242
	private InputField seedField;
}
